﻿using System;
using System.Collections.Generic;

using Gonte.Reflection;

using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Reflection;

namespace MyUtilitiesTest
{
    [TestClass()]
    public class ObjectTraversalTest
    {
        private TestContext testContextInstance;

        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        public class ObjectWithProperties
        {
            private int int_;

            public int Int
            {
                get { return int_; }
                set { int_ = value; }
            }

            private ComplexProperty1 prop1_;

            public ComplexProperty1 Prop1
            {
                get { return prop1_; }
                set { prop1_ = value; }
            }

            private List<ComplexProperty2> prop2_;

            public List<ComplexProperty2> Prop2
            {
                get { return prop2_; }
                set { prop2_ = value; }
            }
        }

        public class ComplexProperty1
        {
        }

        public class ComplexProperty2
        {
        }

        [TestMethod()]
        public void ObjectTraversalTraverseComplexPropertiesTest()
        {
            Object @object = new ObjectWithProperties();

            int complexPropertiesCount = 0;
            int collectionCount = 0;

            ObjectTraversal.TraverseComplexPropertyHandler traverseComplexProperty = delegate(TypeAccessor typeAccessor, String propertyName)
            {
                ++complexPropertiesCount;
            };

            ObjectTraversal.TraverseComplexProperties(@object, traverseComplexProperty);

            Assert.AreEqual(2, complexPropertiesCount);
        }
    }
}
